<?php
$this->breadcrumbs = array(
    ResourceType::$names[$type],
);
?>

<?php /** @var BootActiveForm $form */
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'job',
    'type'=>'search',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>
<div class="box">
<?php echo $form->dropDownListRow($model, 'res_frequency', Frequency::$names, array('class'=>'input-small')); ?>
&nbsp;&nbsp;
<?php echo $form->dropDownListRow($model, 'product_id', Product::listItems(), array('class'=>'input-medium')); ?>
&nbsp;&nbsp;
<?php echo $form->textFieldRow($model, 'res_name', array('class'=>'input-large', 'prepend'=>'<i class="icon-search"></i>')); ?>
&nbsp;&nbsp;
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'搜索')); ?>
</div>

<script>
function reloadGrid(data) {
    $.fn.yiiGridView.update('resource-grid');
}
function checkSelect() {                                                  
    if($.fn.yiiGridView.getSelection("resource-grid") == "") {
        alert('请选择至少一条记录');                                                    
        return false;                                                  
    }
    else {
        return true;
    }
}
</script>

<div class="btn-toolbar">

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'danger',
    'buttonType'=>'ajaxSubmit',
    'size'=>'small',
    'icon'=>'remove white',
    'label'=>'删除资源', 
    'url'=>array('resource/ajaxDelete'), 
    'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要删除吗?',
    ),

)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'label'=>'新建资源',
    'icon'=>'plus white',
    'url'=>array('resource/create', 'type' => $_GET['type']),
    'size'=>'small',
     
)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'label'=>'手动执行',
    'icon'=>'hand-right white',
    'size'=>'small',
    'htmlOptions'=>array(
        'data-toggle'=>'modal',
        'data-target'=>'#myModal',
    ),
)); ?>

</div>

<?php $this->widget('bootstrap.widgets.TbGridView', array(
	'id'=>'resource-grid',
    'type'=>'striped bordered condensed',
    'dataProvider'  =>  $dataProvider,
    'pager'=>array(
        'class'=>'CLinkPager',           
        'nextPageLabel'=>'下一页',           
        'prevPageLabel'=>'上一页',           
        'header'=>'',   
    ),   
    'selectableRows'=> 2,
    'summaryText'   =>  '显示{start}-{end}条.共{count}条记录,当前第{page}页',
    'template'      =>  '{items}{pager}',
    'columns'       =>  array(
       array(
			'id'    =>  'autoId',
            'class' =>  'CCheckBoxColumn',
        ),
        array(
            'header'=>  '#',
            'name'  =>  'res_id',
            'value' =>  '$data->res_id'
        ),
       array(
            'name'  =>  'res_name',
            'type'  =>  'raw',
            'value' =>  'CHtml::link(CHtml::encode($data->res_name), Yii::app()->controller->createUrl("resource/update", array("id"=>$data->res_id)))',
        ),
        array(
            'name'  =>  'product_id',
            'value' =>  '$data->product->product_name'
        ),
        array(
            'name'  =>  'res_type',
            'value' =>  'ResourceType::$names[$data->res_type]'
        ),
        array(
            'name'  =>  'res_frequency',
            'value' =>  'Frequency::$names[$data->res_frequency]'
        ),
        array(
            'name'  =>  'res_desc',
            'value' =>  '$data->res_desc'
        ),
       
        array(
            'class' =>  'bootstrap.widgets.TbButtonColumn',
             'template'=>'{view}{delete}',           
             'buttons'=>array(
                 'view'  =>  array(
                     'label'    =>  '物理资源列表',
                     'url'      =>  'Yii::app()->controller->createUrl("resource/physical", array("id"=>$data->res_id, "type"=>$data->res_type))',
                     ), 
                 'delete'  =>  array(
                     'label'    =>  '删除资源',
                     'url'      =>  'Yii::app()->controller->createUrl("resource/delete", array("id"=>$data->res_id))',
                     ), 
                ),

            ),
        ),
    ));
?>
<?php $this->endWidget(); ?>
